package com.wangzh.concurrent.lock.deadlock;

public class Demo {
    public static void main(String[] args) {
        String a ="a";
        String b = "b";

        new Thread(new MyThread(a,b),"1").start();
        new Thread(new MyThread(b,a),"2").start();
    }
}

class MyThread implements Runnable {
    private String lock1;
    private String lock2;

    public MyThread(String lock1, String lock2) {
        this.lock1 = lock1;
        this.lock2 = lock2;
    }

    @Override
    public void run() {

        synchronized (lock1){

            System.out.println(Thread.currentThread().getName()+"lock1"+lock1);
            synchronized (lock2){
                System.out.println(Thread.currentThread().getName()+"lock2"+lock2);
            }
        }
    }
}
